<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel" >
        <el-form-item class="no-warn-item" label="部门领域：" prop="depModel">
          <hey-select v-model="formModel.depModel" :in-clude-keys="depModelList" filterable clearable clcd="dep_model_cd"/>
        </el-form-item>
        <el-form-item class="no-warn-item" label="文件代码：" prop="fileCd">
          <el-input
            v-model="formModel.fileCd"
            placeholder="文件代码"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="文件名称：" prop="fileNm">
          <el-input
            v-model="formModel.fileNm"
            placeholder="文件名称"
            class="filter-item "
            clearable
          />
        </el-form-item>
        <el-form-item class="no-warn-item" label="注册日期：" prop="registDate">
          <el-date-picker
            v-model="formModel.registDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item class="no-warn-item" label="解析状态：" prop="paraseState">
          <hey-select v-model="formModel.paraseState" clcd="parase_state_cd" />
        </el-form-item>
        <el-form-item class="no-warn-item" label="上传方式：" prop="fileUploadType">
          <hey-select v-model="formModel.fileUploadType" clcd="file_upload_type_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission(['operate'])" plain @click="upload" >文件导入</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :columns="columns" :is-select="false">

    </hey-table>

    <el-dialog
      v-if="showUploadDialog"
      :close-on-click-modal="false"
      title="文件上传"
      :visible.sync="showUploadDialog"
      width="80%"
    >
      <upload @uploadSuc="queryList" />
    </el-dialog>

  </div>
</template>

<script>
  import {mapGetters} from "vuex";

  export default {
    name: 'FileImport',
    components: {
      Upload: () => import('./upload'),
    },
    props: {},
    data() {
      return {
        dialogVisible: false,
        showUploadDialog: false,
        formModel: {
          fileCd: '',
          fileNm: '',
          paraseState: '',
          registDate: '',
          depModel: '',
          fileUploadType: '',
        },
        columns: [
          { title: '部门领域', key: 'depModel', clcd: 'dep_model_cd'},
          { title: '文件编号', key: 'fileId'},
          { title: '文件代码', key: 'fileCd'},
          { title: '文件名称', key: 'fileNm'},
          { title: '上传方式', key: 'fileUploadType',clcd: 'file_upload_type_cd'},
          { title: '注册日期', key: 'registDate'},
          { title: '注册时间', key: 'registTime'},
          { title: '解析状态', key: 'paraseState',clcd: 'parase_state_cd'},
          { title: '错误信息', key: 'paraseErrMsg' },
          { title: '任务编号', key: 'pcsgId'},
        ]
      }
    },
    computed: {
      ...mapGetters([
        'depModelList'
      ])
    },
    mounted() {
      this.queryList(false)
    },
    methods: {
      queryList(isStayPage) {
        if(!this.formModel.registDate){
          //到期日期重置后BUG 必须手动再清一次
          this.formModel.registDate = ''
        }
        this.$refs.table.query('/file/importQuery', this.formModel, '', isStayPage)
      },
      upload(){
        this.showUploadDialog = true
      },
      uploadSuc(){
        this.queryList(false)
      }

    }
  }
</script>


